package com.basics.framework.security.service;/*
package com.basics.framework.security.service;


import com.basics.user.exception.CustomException;
import com.basics.user.utils.MessageUtils;
import com.basics.framework.manager.AsyncManager;
import com.basics.framework.manager.factory.AsyncFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class SysLoginService {
    @Autowired
    private TokenService tokenService;
    @Resource
    private AuthenticationManager authenticationManager;

    public SysLoginService() {
    }

    public String login(String username, String password) {
        Authentication authentication = null;

        try {
            authentication = this.authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, password));
        } catch (Exception var5) {
            if (var5 instanceof BadCredentialsException) {
                AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, "Error", MessageUtils.message("user.password.not.match", new Object[0]), new Object[0]));
                throw new UserPasswordNotMatchException();
            }

            AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, "Error", var5.getMessage(), new Object[0]));
            throw new CustomException(var5.getMessage());
        }

        AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, "Success", MessageUtils.message("user.login.success", new Object[0]), new Object[0]));
        LoginUser loginUser = (LoginUser)authentication.getPrincipal();
        return this.tokenService.createToken(loginUser);
    }
}
*/
